import UICore from "../../../../Core/Res/UICore";
import * as fgui from "fairygui-cc";
import AbstractUIWindow from "../../window/AbstractUIWindow";
import AudioManager from "../../../../Core/Audio/AudioManager";
import SdkTool from "../../../../Core/Sdk/SdkTool";
import { ViewManager } from "../../base/ViewManager";
import { GameModels } from "../../socket/GameModels";
import EventMgr from "../../../../Core/Event/EventMgr";
import ModuleWindow from "../../window/ModuleWindow";
import WindowObject from "../../window/WindowObject";

export class RoomWindow extends AbstractUIWindow {
    private creatRoom: fgui.GButton;
    private join: fgui.GButton;
    private input: fgui.GTextInput;
    protected getResList(): Array<string> {
        return [`Plane`];
    }
    protected onInit(): void {
        this._view = UICore.createObject("Plane", "RoomWindow").asCom;
    }
    protected onShow(): void {
        // EventMgr.on(`event_RespEnterRoom`, this.onRespEnterRoom);
        EventMgr.on(`event_RespCreateRoom`, this.onRespCreateRoom);
        this.creatRoom.onClick(this.clickcreatRoom, this);
        this.join.onClick(this.clickjoin, this);
    }
    private clickcreatRoom(): void {
        GameModels.lobby.send_ReqCreateRoom();
    }
    private onRespCreateRoom(data: any): void {
        ViewManager.ins.showtips("创建房间成功");
        ModuleWindow.ins.openView(WindowObject.ins.PlayView, true);
    }
    private clickjoin(): void {
        if (this.input.text == "") {
            ViewManager.ins.showtips("请输入房间号");
            return;
        }
        GameModels.lobby.send_ReqEnterRoom(this.input.text);


    }
    // private onRespEnterRoom(data: any): void {
    //     ViewManager.ins.showtips("进入房间成功");
    //     ModuleWindow.ins.openView(WindowObject.ins.PlayView, true);
    // }
}